package com.potenza.training.reply.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.potenza.training.reply.entity.ReplyGroupEntity;
import com.potenza.training.reply.service.ReplyGroupService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 答辩室
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-22 15:57:42
 */
@RestController
@RequestMapping("reply/replygroup")
public class ReplyGroupController {
    @Autowired
    private ReplyGroupService replyGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("reply:replygroup:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = replyGroupService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("reply:replygroup:info")
    public R info(@PathVariable("id") Long id){
		ReplyGroupEntity replyGroup = replyGroupService.getById(id);

        return R.ok().put("replyGroup", replyGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("reply:replygroup:save")
    public R save(@RequestBody ReplyGroupEntity replyGroup){
		replyGroupService.save(replyGroup);

        return R.ok().put("id",replyGroup.getId());
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("reply:replygroup:update")
    public R update(@RequestBody ReplyGroupEntity replyGroup){
		replyGroupService.updateById(replyGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("reply:replygroup:delete")
    public R delete(@RequestBody Long[] ids){
		replyGroupService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 分页
     */
    @RequestMapping("/findAll/{pageNum}/{pageSize}")
    @RequiresPermissions("reply:replygroup:list")
    public R listAll(@RequestBody Map map,@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        Page<ReplyGroupEntity> page = replyGroupService.findAll(map,pageNum,pageSize);

        return R.ok().put("page", page);
    }

    @GetMapping("findAlls")
    public List<ReplyGroupEntity> findAlls(){
        return replyGroupService.findAlls();
    }

    /**
     * 获取所有的答辩室列表
     */
    @RequestMapping("/all")
    public R findAll(){
        List<ReplyGroupEntity> list = replyGroupService.list();
        return R.ok().put("data", list);
    }
}
